<?php
namespace Common\Model;
use Think\Model;
class LiveCompetitorModel extends VRLiveModel
{
	
	protected $_validate = array(
			array('real_name', 'require', '姓名不能为空！', 0, 'regex', CommonModel:: MODEL_BOTH),
			array('birthday', 'require', '生日不能为空！', 0, 'regex', CommonModel:: MODEL_BOTH),
			array('nickname', 'require', '绰号不能为空！', 0, 'regex', CommonModel:: MODEL_BOTH),
			array('weight', 'number', '请输入正确的体重(数字)！', 2, 'regex', CommonModel:: EXISTS_VALIDATE  ),
			array('popular_value', 'number', '请输入正确的人气值(数字)！', 2, 'regex', CommonModel:: EXISTS_VALIDATE  )
	);
	
    protected $_auto = array(
			array('create_time','mGetDate',CommonModel:: MODEL_INSERT,'callback'),
    		array('update_time','mGetDate',CommonModel:: MODEL_UPDATE,'callback'),
	);
	
	//用于获取时间，格式为2012-02-03 12:12:12,注意,方法不能为private
	function mGetDate() {
		return date('Y-m-d H:i:s');
	}
	
	public function queryLiveCompetitorList($id, $sex = -1, $name = null, $nickname = null, $pageStart, $pageSize){
		$where = array();
		if('' != $id){
			$where['competitor_id'] = array('EQ', $id);
		}
		if(-1 != $sex){
			$where['sex'] = array('EQ', $sex);
		}
		if($name && !empty($name)){
			$where['real_name'] = array('like','%'.$name.'%');
		}
		$where['status'] = array('EQ', 1);
		if($nickname && !empty($nickname)){
			$where['nickname'] = array('like','%'.$nickname.'%');
		}
		
		$list = $this->where($where)->limit($pageStart, $pageSize)->select();
		return $list;
	}
	
	public function queryLiveCompetitorCount($id, $sex = -1, $name = null, $nickname = null){
	$where = array();
		if($id){
			$where['competitor_id'] = array('EQ', $id);
		}
		if(-1 != $sex){
			$where['sex'] = array('EQ', $sex);
		}
		if($name && !empty($name)){
			$where['real_name'] = array('like','%'.$name.'%');
		}
		$where['status'] = array('EQ', 1);
		if($nickname && !empty($nickname)){
			$where['nickname'] = array('like','%'.$nickname.'%');
		}
		return $this->where($where)->count();
	}
	
	public function getLiveCompetitorList(){
		$list = $this->where(array('status'=>1))->select();
		return $list;
	}
}

